<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicFormats } from "../formats";

const props = withDefaults(defineProps<FormProps>(), {
  id: String, // 添加 id prop
  formInline: () => ({
    id: "",
    name: "",
    mobile: "",
    car_number: "",
    car_no_color: -1,
    car_type: -1
  })
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

const { carColorOptions, carTypeOptions } = usePublicFormats();

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="名称" prop="name">
      <el-input
        v-model="newFormInline.name"
        clearable
        placeholder="请输入名称"
      />
    </el-form-item>
    <el-form-item label="手机号" prop="mobile">
      <el-input
        v-model="newFormInline.mobile"
        clearable
        placeholder="请输入手机号"
      />
    </el-form-item>
    <el-form-item label="车牌号" prop="car_number">
      <el-input
        v-model="newFormInline.car_number"
        clearable
        placeholder="请输入车牌号"
      />
    </el-form-item>
    <el-form-item label="车牌颜色" prop="car_no_color">
      <el-select
        v-model="newFormInline.car_no_color"
        placeholder="请选择车牌颜色"
        class="w-full"
        clearable
      >
        <el-option
          v-for="item in carColorOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="车辆类型" prop="car_type">
      <el-select
        v-model="newFormInline.car_type"
        placeholder="请选择车辆类型"
        clearable
      >
        <el-option
          v-for="item in carTypeOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="有效期" prop="out_time">
      <el-date-picker
        v-model="newFormInline.out_time"
        prop="out_time"
        type="datetime"
        :shortcuts="timeFrame"
        format="YYYY-MM-DD HH:mm:ss"
        value-format="YYYY-MM-DD HH:mm:ss"
        range-separator="至"
        start-placeholder="开始日期时间"
        end-placeholder="结束日期时间"
        :popper-options="{
          placement: 'bottom-start'
        }"
      />
    </el-form-item>
    <el-form-item label="客户类型" prop="order_type">
      <el-select
        v-model="newFormInline.order_type"
        placeholder="请选择类型"
        clearable
      >
        <el-option label="小强停车" :value="1" />
        <el-option label="泊安飞" :value="2" />
      </el-select>
    </el-form-item>
  </el-form>
</template>
